/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package de.swta.freezay.database.wicketAdapter;

import de.swta.freezay.database.JPAController;
import de.swta.freezay.database.dbEntities.Category;
import java.util.Iterator;
import org.apache.wicket.extensions.markup.html.repeater.util.SortParam;
import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider;
import org.apache.wicket.model.IModel;

/**
 * A SortableDataProvider for category entities
 *
 * @author Christian Baeumer
 * @see SortableDataProvider
 */
public class CategoryDataProvider extends SortableDataProvider<Category>  {

    public CategoryDataProvider() {
        setSort("name", true);
    }

    @Override
    public Iterator iterator(int first, int count) {
        SortParam sp = getSort();

        return JPAController.CategoryJpaController.findCategoryEntities(
                count, first, sp.getProperty(), sp.isAscending()).iterator();
    }

    @Override
    public int size() {
        return JPAController.CategoryJpaController.getCategoryCount();
    }


    @Override
    public IModel<Category> model(Category cat) {
        return new DetachableCategoryModel(cat);
    }


}